functor CfgMain (S : CFGMAIN_STRUCTS) : CFGMAIN =
struct
  open S
  
  structure Ir = Ir
  structure Cfg = Cfg
  
  structure Cfgize = Cfgize (structure Ir = Ir
                             structure Cfg = Cfg)
                             
  structure Shrink = Shrink (structure Cfg = Cfg)
  
  structure DeSsa = DeSsa (structure Cfg = Cfg)
  
  val tag = true
                          
  fun ir2cfg new =
      let val new = Cfgize.trans new          
      in  if !Control.doToSsa
          then let val new = Shrink.shrink new
                   val _ = if tag
                           then Cfg.Program.toDot (new, "beforeDeSsa")
                           else ()
                   val new = DeSsa.trans new
                   val _ = if tag
                           then Cfg.Program.toDot (new, "DeSsa")
                           else ()
               in  new
               end
          else new
      end
  
end
